# CMakeLists.txt for template-cpp-learn

# Get all .cpp files in the directory
file(GLOB TEMPLATE_SOURCES "*.cpp")

# Create executables for each source file
foreach(SOURCE ${TEMPLATE_SOURCES})
    get_filename_component(EXEC_NAME ${SOURCE} NAME_WE)
    add_executable(${EXEC_NAME} ${SOURCE})
    
    # Set target properties
    set_target_properties(${EXEC_NAME} PROPERTIES
        CXX_STANDARD 20
        CXX_STANDARD_REQUIRED ON
    )
    
    # Add custom target to run each executable
    add_custom_target(run_${EXEC_NAME}
        COMMAND ${EXEC_NAME}
        DEPENDS ${EXEC_NAME}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Running ${EXEC_NAME} executable"
    )
endforeach()

# Create a custom target to run all template examples
add_custom_target(run_all_templates
    COMMENT "Running all template learning examples"
)

# Add dependencies for the run_all_templates target
foreach(SOURCE ${TEMPLATE_SOURCES})
    get_filename_component(EXEC_NAME ${SOURCE} NAME_WE)
    add_dependencies(run_all_templates run_${EXEC_NAME})
endforeach()
